package org.example.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.example.model.entity.User;
import org.example.model.data.UserData;
import org.example.mapper.UserDaoMapper;
import org.example.response.ApiResponse;
import org.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import java.util.Optional;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @Autowired
    private UserDaoMapper userDaoMapper;
    @Autowired
    private RedisTemplate redisTemplate;

    //获取用户信息
    @RequestMapping("/{id}")
    public ApiResponse<User> getUserById(@PathVariable String id) {
        Optional<User> optionalUser = Optional.ofNullable(userService.getById(id));
        if (optionalUser.isPresent()) {
            return ApiResponse.success(optionalUser.get());
        } else {
            return ApiResponse.error("用户不存在！");
        }

    }

}
